package ge.telasi.tasks.ui.structure;

import java.awt.Component;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JList;

/**
 * @author dimitri
 */
public class StructureTypeCombo extends JComboBox {
    private static final long serialVersionUID = 3576035971326868069L;
    
    public StructureTypeCombo() {
        setModel(new DefaultComboBoxModel(StructureUtils.allTypes()));
        setRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value instanceof Integer) {
                    Integer type = (Integer) value;
                    setText(StructureUtils.getName(type));
                    setIcon(StructureUtils.getIcon(type));
                }
                return this;
            }
        });
    }

    public int getType() {
        return (Integer) getSelectedItem();
    }

    public void setType(int type) {
        setSelectedItem(type);
    }

}
